<?php
/**
 * Created by PhpStorm.
 * User: code001
 * Date: 20-6-19
 * Time: 下午1:27
 */
namespace  App\Models;
use App\Lib\Request\ResultObject;
use Illuminate\Database\Eloquent\Model;

/**
 * Class Users
 * @package App\Models
 * @property integer $id
 * @property string $username
 *
 */
class User extends Model implements IReadable
{
    protected $table = "admin_users";

    protected $guarded = [];

    public function attributeLabels()
    {
       return [
            'id' => 'ID',
            'username' => '用户名',
            'password' => [
                'type' => 'password',
                'label' => '密码'
            ],
           'mobile' => '代理手机号',
        //   'pdd_pid' => '拼多多推广ID(p_id)',
         //  'jd_pid' => '京东推广ID(positionId)',
           'taobao_pid' => '淘宝推广ID(rid)',
           'tuid' => [
               'type' => 'integer',
               'label' => '第三方UID'
           ]
       ];
    }



    public function getHashCode()
    {
        return hash("md5", $this->id);
    }

    /**
     * @return ResultObject
     */
    public static function getConfig($uid = null)
    {
        if (empty($uid)) {
            $uid = \Encore\Admin\Facades\Admin::guard()->id();
        }
        /** @var Model $data */
        $data = self::where("id", $uid)->first();
        $o = new ResultObject(['uid' => $uid, 'pdd_pid' => $data->pdd_pid, "jd_pid" => $data->jd_pid, "taobao_pid" => $data->taobao_pid]);
        return $o;
    }

    public static function getWxid($uid = null)
    {
        if (empty($uid)) {
            $uid = \Encore\Admin\Facades\Admin::guard()->id();
        }
        $data = self::where("id", $uid)->first();
        return $data->wxid;
    }
}